<%--
  Created by IntelliJ IDEA.
  User: webrx
  Date: 2017/6/17
  Time: 11:52
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <script src="../js/jquery-3.2.1.min.js"></script>
    <title>用户注册</title>
    <style>
        .form{
            width:500px ;
            height: 300px;
           /* padding: 50px;*/
            margin: auto;
            background-color: #adaba4;
        }
          input{
              padding:3px;
            margin: 10px 20px;
        }
        .yes{
            color: greenyellow;
        }
        .no{
            color:hotpink;
        }
    </style>
    <script>
       /* function getCheckboxValue(love) {
            var cities = document.getElementsByName(love);
            var selectCities = [];
            //var sc = "";
            for (var i = 0; i < cities.length; i++) {
                if (cities[i].checked) {
                    selectCities[selectCities.length] = cities[i].value;
                    //selectCities.push(cities[i].value);
                    //sc += cities[i].value + ",";
                    //三种方式效率比较："+=" > "arr[arr.length] = value" > arr.push(value)，是这样吗？
                }
            }
            document.getElementById('dispCity').value = selectCities.join();
            //document.getElementById('dispCity').value = sc;
        }*/
        $(function () {
            $('input[name=user]').keyup(function () {
                var v =$(this).val().trim();
                var t =$(this);
                $('#msg').removeClass('yes');
                $('#msg').removeClass('no');
               /* $('#msg').removeClass();*/
                $.post('../usertable.do',{action:'yan',av:v},function (d) {

                    if(d=='yes'){
                        $('#msg').addClass('yes').html("恭喜此用户名可以用")
                    }else{
                        $('#msg').addClass('no').html("此用户名已使用")

                    }
                },'text');
            })
            /*提交表单*/
            $('input[type=submit]').click(function () {
                var name=$('#name').val().trim();
                if(name==''){
                    alert('用户名不能为空')
                    return;
                };
                var pass01 =$('#password').val().trim();
                var pass02 =$('#password2').val().trim();
                if(pass01!=pass02){
                    alert("两次密码不同请从新填写")
                    $('#password').val('');
                    $('#password2').val('');
                    return;
                };
                var gender =$(':checked')[0].value;


                $.ajax({
                    type:'POST',
                    url:'../usertable.do',
                    data:{action:'add',n:name,p:pass01,g:gender},
                    dataType:'text',
                    cache:'false',
                    async:'true',
                    success:function (d) {
                        alert(d);
                        setTimeout(location.href='../lunboadd?action=index',6000)
                    }
                })

            })
        })
    </script>
</head>
<body>

    用户名：　<input type="text" name="user" id="name">&nbsp;<span id="msg"></span><br>
    用户密码：<input type="text" name="password" id="password"><br>
    确认密码：<input type="text" name="password2" id="password2"><br>
    性别：　　<input type="radio" name="gender" value="男" checked>男
         　　<input type="radio" name="gender" value="女">女<br>

   <%-- 爱好:　　<input type="checkbox" name="love"  value="篮球">篮球&nbsp;
            <input type="checkbox" name="love"  value="足球">足球&nbsp;
            <input type="checkbox" name="love"  value="排球">排球<br>
--%>
    <input type="checkbox">请阅读《Vancl凡客诚品服务条款》<br><br>
    <input type="submit" value="提交" >&nbsp;&nbsp; <input type="reset" value="重填">


</body>
</html>
